﻿AlertType = {
    Success: 0,
    Error: 1,
    Warning: 2,
    Info: 3
}
function Alert() {
    var message = ""
    this.Name = "";
    this.Type = AlertType.Warning;
    this.AutoClose = true;
    this.HasMessage = function () {
        return message.length > 0;
    }
    this.AddMessage = function (text) {
        message += text + "<br />";
    }
    this.Show = function () {
        var titulo = "";
        var classe = "";
        if (this.Type == AlertType.Error) {
            //titulo = "Ocorreram os seguintes erros";
            classe = "alert alert-error";
        }
        if (this.Type == AlertType.Success) {
            //titulo = "Informação";
            classe = "alert alert-success";
        }
        if (this.Type == AlertType.Warning) {
            //titulo = "Alerta";
            classe = "alert alert-block";
        }
        if (this.Type == AlertType.Info) {
            classe = "alert alert-info";
        }
        var html = "<div class='" + classe + "' alert=\"true\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>" +
                    "<h4 class=\"alert-heading\" id=\"alert$Title\">" + titulo + "</h4>" +
                    "<p id=\"alert$Text\">" + message + "</p></div>";

        if (this.Name == "")
            $("div[alertItem='true']").html(html);
        else
            $("div[alert-name='" + this.Name + "']").html(html);
        $(".alert").alert()
        if(this.AutoClose)
            setTimeout(function () {
                $('div[alert="true"]').hide();
            }, 20000);
        //alert alert-block alert-error fade in
    }
    return {
        Name: this.Name,
        Type: this.Type,
        AutoClose: this.AutoClose,
        HasMessage: this.HasMessage,
        AddMessage: this.AddMessage,
        Show: this.Show
    }
}